package preprocess;
import ICTCLAS.I3S.AC.ICTCLAS50;
import idx.Searcher;
import java.util.*;
import java.util.regex.*;
import java.io.*;
import datastructure.*;

public class preanalyze {
	public ArrayList<String> keyword;
	public Querystruct Querys;
	public preanalyze()
	{
		keyword = new ArrayList<String>();
	}
	public static void main(String[] args)
	{
		try
		{
			preanalyze preprocess = new preanalyze();
			//字符串分词         
			String sInput;
			Scanner t = new Scanner(System.in);
			
			sInput = t.nextLine();
			//sInput = args[0];
			preprocess.process(sInput);
			return;
		}
		catch (Exception ex)
		{
			System.out.println(ex);
		}
	}
	
	public void process(String sInput)
	{
		try
		{
			Pattern p=Pattern.compile("[\"“《](.*?)[\"”》]");//也可满足中文双引号里的匹配
	        Matcher m=p.matcher(sInput);
	        while(m.find()){
	            //System.out.println(m.group(1));
				this.keyword.add(m.group(1).toString());
	        }
			sentence input = new sentence(sInput);
			Querys = new Querystruct(input,false);
			String query = this.querycreate(Querys);
			Searcher s = new Searcher(5,"Wiki");
			System.out.println(query);
			s.Search("context", Querys);
			s.ShowResult();
		}
		catch (Exception ex)
		{
			System.out.println(ex);
		}
	}
	
	public String querycreate(Querystruct query)
	{
		String queryStr = "";
		ArrayList<word> temp = query.keyword;
		for(int i = 0; i < query.words.size(); i++)
		{
			System.out.println(query.words.get(i).content+" "+query.words.get(i).pos+" "+query.words.get(i).position);
		}	
		int size = temp.size();
		for(int i = 0; i < size; i++)
		{
			queryStr += temp.get(i).content;
			if(i != size-1)
				queryStr += " ";
		}
		System.out.println(queryStr);
		return queryStr;
	}
	
}
